1722C - Word Game - CodeForces Solution


data structures implementation

Please click on ads to support us..

Python Code:

def solve():
    n = int(input())
    a1 = list(map(str, input().split()))
    a2 = list(map(str, input().split()))
    a3 = list(map(str, input().split()))
    a4 = a1 + a2 + a3
    d = {}
    c1 = 0
    c2 = 0
    c3 = 0
    for i in range(n*3):
        try:
            d[a4[i]] = d[a4[i]] + 1
        except:
            d[a4[i]] = 1
    for i in range(n):
        if d[a1[i]]==1:
            c1+=3
        elif d[a1[i]]==2:
            c1+=1
    for i in range(n):
        if d[a2[i]]==1:
            c2+=3
        elif d[a2[i]]==2:
            c2+=1
    for i in range(n):
        if d[a3[i]]==1:
            c3+=3
        elif d[a3[i]]==2:
            c3+=1

    print(str(c1) + " " + str(c2) + " " + str(c3))


if __name__ == '__main__':
    t = int(input())
    for i in range(t):
        solve()

C++ Code:

#include <bits/stdc++.h>
#define F first
#define S second
#define int long long
#define H unsigned long long
#define V vector<int>
#define M vector<vector<int>> 
#define ld long double
#define C complex<ld>
#define X real()
#define Y imag()
using namespace std;

const long double PI = acos(-1);
const int MAXN = 2 * 1e5;
const int MOD = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  int t; cin >> t;
  while (t --) {
    int n; cin >> n;

    vector<vector<string>> v(n, vector<string> (3));
    map<string, int> m;

    for (int i = 0; i < 3; i ++) {
      for (int j = 0; j < n; j ++) {
        cin >> v[j][i];
        m[v[j][i]] ++;
      }
    } 

    int a = 0, b = 0, c = 0;

    for (int i = 0; i < n; i ++) {
      string an = v[i][0];

      int cnt = m[an];

      if (cnt == 1) {
        a += 3;
      } else if (cnt == 2) {
        a ++;
      }
    }
    for (int i = 0; i < n; i ++) {
      string an = v[i][1];

      int cnt = m[an];

      if (cnt == 1) {
        b += 3;
      } else if (cnt == 2) {
        b ++;
      }
    }
    for (int i = 0; i < n; i ++) {
      string an = v[i][2];

      int cnt = m[an];

      if (cnt == 1) {
        c += 3;
      } else if (cnt == 2) {
        c ++;
      }
    }

    cout << a << " " << b << " " << c << "\n";
  }

  return 0;
}
  		 	  	   		 	  					 	  			


Comments

Submit
0 Comments
More Questions

1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh
1721E - Prefix Function Queries
977E - Cyclic Components
1140D - Minimum Triangulation
75C - Modified GCD
1722A - Spell Check
1722B - Colourblindness
1722D - Line
1722C - Word Game
1722G - Even-Odd XOR
552E - Vanya and Brackets
933A - A Twisty Movement
1722F - L-shapes
1196B - Odd Sum Segments
1325D - Ehab the Xorcist
552B - Vanya and Books
1722E - Counting Rectangles
168A - Wizards and Demonstration
168B - Wizards and Minimal Spell
7A - Kalevitch and Chess
912B - New Year's Eve
1537C - Challenging Cliffs
879B - Table Tennis